
#import "SMMineSettingsViewController.h"
@implementation SMMineSettingsViewController { NSArray *_items; }
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"设置";
    self.view.backgroundColor=UIColor.systemGroupedBackgroundColor;
    self.tableView.backgroundColor=UIColor.systemGroupedBackgroundColor;
    self.tableView = [[UITableView alloc] initWithFrame:self.tableView.frame style:UITableViewStyleInsetGrouped];
    _items=@[@{@"t":@"消息通知", @"type":@"switch"},
             @{@"t":@"仅 Wi‑Fi 下加载图片", @"type":@"switch"},
             @{@"t":@"清除缓存", @"type":@"action"},
             @{@"t":@"退出登录", @"type":@"destructive"}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; }
- (NSInteger)tableView:(UITableView*)t numberOfRowsInSection:(NSInteger)s{ return _items.count; }
- (UITableViewCell*)tableView:(UITableView*)t cellForRowAtIndexPath:(NSIndexPath*)i{
    NSDictionary *d=_items[i.row];
    NSString *type=d[@"type"];
    if ([type isEqualToString:@"switch"]) {
        UISwitch *sw=[UISwitch new];
        UITableViewCell *c=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        c.textLabel.text=d[@"t"]; c.accessoryView=sw;
        return c;
    } else {
        UITableViewCell *c=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        c.textLabel.text=d[@"t"];
        if ([type isEqualToString:@"destructive"]) c.textLabel.textColor=UIColor.systemRedColor;
        c.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        return c;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *d=_items[indexPath.row];
    if ([d[@"type"] isEqualToString:@"action"]) {
        UIAlertController *ac=[UIAlertController alertControllerWithTitle:@"清除缓存" message:@"缓存已清理。" preferredStyle:UIAlertControllerStyleAlert];
        [ac addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:ac animated:YES completion:nil];
    }
    if ([d[@"type"] isEqualToString:@"destructive"]) {
        UIAlertController *ac=[UIAlertController alertControllerWithTitle:@"退出登录" message:@"确定要退出吗？" preferredStyle:UIAlertControllerStyleActionSheet];
        [ac addAction:[UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleDestructive handler:nil]];
        [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
        [self presentViewController:ac animated:YES completion:nil];
    }
}
@end
